package com.jwenfeng.library.pulltorefresh.view;

import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.jwenfeng.library.R;

public class YohoRefreshView extends FrameLayout implements HeadView {

    private ImageView yoho_img;
    private View headView;
    private AnimationDrawable refreshAnim;

    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
    public YohoRefreshView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
    private void init(){
        headView = LayoutInflater.from(getContext()).inflate(R.layout.layout_yoho,null);
        addView(headView);
        yoho_img = headView.findViewById(R.id.yoho_img);
        //读取帧动画并设置给ImageView
        refreshAnim = (AnimationDrawable) getContext().getResources().getDrawable(R.drawable.head_anim);
        yoho_img.setBackground(refreshAnim);
    }

    @Override
    public void begin() {
        Log.e("ZXY","begin()");
    }

    @Override
    public void progress(float progress, float all) {

    }

    @Override
    public void finishing(float progress, float all) {
           refreshAnim.stop();
    }

    @Override
    public void loading() {
        //开始播放帧动画
        refreshAnim.start();
    }

    @Override
    public void normal() {

    }

    @Override
    public View getView() {
        return this;
    }
}
